const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CustomerId: 0,
    CustomerNo: '',
    CustomerName: '',
    ComapnyAddress: '',
    LoginNo: '',
    Mb: '',
    Password: '',
    IsActive: true,
    showTopTips: false,
    errorText: "错误"
  },
  changeText: function (e) {
    let name = e.currentTarget.dataset.name;
    let nameMap = {}
    nameMap[name] = e.detail && e.detail.value
    this.setData(nameMap)
  },
  switchStop: function (e) {
    let name = e.currentTarget.dataset.name;
    let nameMap = {}
    nameMap[name] = e.detail && e.detail.value
    this.setData(nameMap)
    console.log(this.data.IsView)
  },
  compReq: function () {
    var that = this
    wx.request({
      url: app.globalData.api + 'User',
      method: "POST",
      header: {
        Authorization: app.globalData.Authorization
      },
      data: {
        CustomerId: this.data.CustomerId,
        CustomerNo: this.data.CustomerNo,
        CustomerName: this.data.CustomerName,
        ComapnyAddress: this.data.ComapnyAddress,
        LoginNo: this.data.LoginNo,
        Mb: this.data.Mb,
        Password: this.data.Password,
        IsActive: this.data.IsActive
      },
      success: function (res) {
        console.log(res)
        if (res.data.Code) {
          wx.navigateBack({
            delta: 1
          })
        } else {
          that.setData({
            showTopTips: true,
            errorText: res.data.Error
          })
          setTimeout(function () {
            that.setData({
              showTopTips: false
            })
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    console.log(options)
    if (options.id) {
      app.req({
        url: 'User/Customer/' + options.id,
        success: function (res) {
          console.log(res)
          var data = res.data
          that.setData({
            CustomerId: options.id,
            CustomerNo: data.CustomerNo,
            CustomerName: data.CustomerName,
            ComapnyAddress: data.ComapnyAddress,
            LoginNo: data.LoginNo,
            Mb: data.Mb,
            Password: data.Password,
            IsActive: data.IsActive
          })
        }
      })
    } else {
      this.setData({
        CustomerId: 0
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})